<template>
  <div class="aplayer-box"><aplayer ref="audio" :autoplay="true" :music="music" /></div>
</template>

<script>
import Aplayer from 'vue-aplayer';
export default {
  components: {
    Aplayer
  },
  props: {
    file: {
      type: Object,
      required: true
    },
    preview: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      music: {
        src: this.file.fileurl[0].play_url,
        title: this.file.filename,
        pic: this.file.cover_url,
        artist: '音频'
      }
    };
  },
  watch: {
    preview(val) {
      if (val === false) {
        this.$refs.audio.pause();
      } else {
        this.$refs.audio.play();
      }
    }
  }
};
</script>

<style scoped>
.aplayer-box {
  width: 100%;
}
</style>
